/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bookshop.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Thibault
 */
@Entity
@Table(catalog = "bookshopdb", schema = "", uniqueConstraints = {
    @UniqueConstraint(columnNames = {"id"})})
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Book.findAll", query = "SELECT b FROM Book b"),
    @NamedQuery(name = "Book.findById", query = "SELECT b FROM Book b WHERE b.id = :id"),
    @NamedQuery(name = "Book.findByIsbn", query = "SELECT b FROM Book b WHERE b.isbn = :isbn"),
    @NamedQuery(name = "Book.findByTitle", query = "SELECT b FROM Book b WHERE b.title LIKE :title"),
    @NamedQuery(name = "Book.findBySummary", query = "SELECT b FROM Book b WHERE b.summary = :summary"),
    @NamedQuery(name = "Book.findByPublicationDate", query = "SELECT b FROM Book b WHERE b.publicationDate = :publicationDate"),
    @NamedQuery(name = "Book.findByBitmapURL", query = "SELECT b FROM Book b WHERE b.bitmapURL = :bitmapURL"),
    @NamedQuery(name = "Book.findByPrice", query = "SELECT b FROM Book b WHERE b.price = :price"),
    @NamedQuery(name = "Book.findByStock", query = "SELECT b FROM Book b WHERE b.stock = :stock"),
    @NamedQuery(name = "Book.findByCreatedDate", query = "SELECT b FROM Book b WHERE b.createdDate = :createdDate"),
    @NamedQuery(name = "Book.findByUpdatedDate", query = "SELECT b FROM Book b WHERE b.updatedDate = :updatedDate"),
    @NamedQuery(name = "Book.findByDeletedDate", query = "SELECT b FROM Book b WHERE b.deletedDate = :deletedDate"),
    @NamedQuery(name = "Book.findBySerie", query = "SELECT b FROM Book b WHERE b.seriesid = :serie"),
    @NamedQuery(name = "Book.findByCategoryId", query = "SELECT b FROM Book b WHERE b.categoryid = :categoryId"),
    @NamedQuery(name = "Book.findByCategory", query = "SELECT b FROM Book b WHERE b.categoryid = :category"),
    @NamedQuery(name = "Book.findByAuthor", query = "SELECT b FROM Book b WHERE :author MEMBER OF b.authorList"),
    @NamedQuery(name = "Book.findByType", query = "SELECT b FROM Book b WHERE :type MEMBER OF b.typeList"),
    @NamedQuery(name = "Book.findByPublisher", query = "SELECT b FROM Book b WHERE :publisher MEMBER OF b.publisherList"),
    @NamedQuery(name = "Book.findByCollection", query = "SELECT b FROM Book b WHERE :collection MEMBER OF b.collectionList")})
public class Book implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(nullable = false)
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 13)
    @Column(nullable = false, length = 13)
    private String isbn;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 100)
    @Column(nullable = false, length = 100)
    private String title;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(nullable = false, length = 255)
    private String summary;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(nullable = false, length = 20)
    private String publicationDate;
    @Size(max = 255)
    @Column(length = 255)
    private String bitmapURL;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Basic(optional = false)
    @NotNull
    @Column(nullable = false, precision = 5, scale = 2)
    private double price;
    @Basic(optional = false)
    @NotNull
    @Column(nullable = false)
    private int stock;
    @Basic(optional = false)
    @NotNull
    @Column(nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdDate;
    @Temporal(TemporalType.TIMESTAMP)
    private Date updatedDate;
    @Temporal(TemporalType.TIMESTAMP)
    private Date deletedDate;
    @ManyToMany(mappedBy = "bookList", fetch = FetchType.LAZY)
    private List<Author> authorList;
    @JoinTable(name = "book_type", joinColumns = {
        @JoinColumn(name = "Book_id", referencedColumnName = "id", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "Type_id", referencedColumnName = "id", nullable = false)})
    @ManyToMany(fetch = FetchType.LAZY)
    private List<Type> typeList;
    @JoinTable(name = "book_collection", joinColumns = {
        @JoinColumn(name = "Book_id", referencedColumnName = "id", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "Collection_id", referencedColumnName = "id", nullable = false)})
    @ManyToMany(fetch = FetchType.LAZY)
    private List<Collection> collectionList;
    @JoinTable(name = "book_publisher", joinColumns = {
        @JoinColumn(name = "Book_id", referencedColumnName = "id", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "Publisher_id", referencedColumnName = "id", nullable = false)})
    @ManyToMany(fetch = FetchType.LAZY)
    private List<Publisher> publisherList;
    @JoinColumn(name = "Series_id", referencedColumnName = "id")
    @ManyToOne(fetch = FetchType.LAZY)
    private Serie seriesid;
    @JoinColumn(name = "Category_id", referencedColumnName = "id")
    @ManyToOne(fetch = FetchType.LAZY)
    private Category categoryid;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "book", fetch = FetchType.LAZY)
    private List<CustomerorderBook> customerorderBookList;

    public Book() {
    }

    public Book(Integer id) {
        this.id = id;
    }

    public Book(Integer id, String isbn, String title, String summary, String publicationDate, String bitmapURL, double price, int stock, Date createdDate) {
        this.id = id;
        this.isbn = isbn;
        this.title = title;
        this.summary = summary;
        this.publicationDate = publicationDate;
        this.bitmapURL = bitmapURL;
        this.price = price;
        this.stock = stock;
        this.createdDate = createdDate;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getIsbn() {
        return isbn;
    }

    public void setIsbn(String isbn) {
        this.isbn = isbn;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getSummary() {
        return summary;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    public String getPublicationDate() {
        return publicationDate;
    }

    public void setPublicationDate(String publicationDate) {
        this.publicationDate = publicationDate;
    }

    public String getBitmapURL() {
        return bitmapURL;
    }

    public void setBitmapURL(String bitmapURL) {
        this.bitmapURL = bitmapURL;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getStock() {
        return stock;
    }

    public void setStock(int stock) {
        this.stock = stock;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public Date getUpdatedDate() {
        return updatedDate;
    }

    public void setUpdatedDate(Date updatedDate) {
        this.updatedDate = updatedDate;
    }

    public Date getDeletedDate() {
        return deletedDate;
    }

    public void setDeletedDate(Date deletedDate) {
        this.deletedDate = deletedDate;
    }

    @XmlTransient
    public List<Author> getAuthorList() {
        return authorList;
    }

    public void setAuthorList(List<Author> authorList) {
        this.authorList = authorList;
    }

    @XmlTransient
    public List<Type> getTypeList() {
        return typeList;
    }

    public void setTypeList(List<Type> typeList) {
        this.typeList = typeList;
    }

    @XmlTransient
    public List<Collection> getCollectionList() {
        return collectionList;
    }

    public void setCollectionList(List<Collection> collectionList) {
        this.collectionList = collectionList;
    }

    @XmlTransient
    public List<Publisher> getPublisherList() {
        return publisherList;
    }

    public void setPublisherList(List<Publisher> publisherList) {
        this.publisherList = publisherList;
    }

    public Serie getSeriesid() {
        return seriesid;
    }

    public void setSeriesid(Serie seriesid) {
        this.seriesid = seriesid;
    }

    public Category getCategoryid() {
        return categoryid;
    }

    public void setCategoryid(Category categoryid) {
        this.categoryid = categoryid;
    }

    @XmlTransient
    public List<CustomerorderBook> getCustomerorderBookList() {
        return customerorderBookList;
    }

    public void setCustomerorderBookList(List<CustomerorderBook> customerorderBookList) {
        this.customerorderBookList = customerorderBookList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Book)) {
            return false;
        }
        Book other = (Book) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.bookshop.entity.Book[ id=" + id + " ]";
    }
    
}
